﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class registration_step1 : DAO.ESWebUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeUI();
        setAttributes();
        if (!Page.IsPostBack)
        {
            LoadCountry();
            //lblShortText.Text = DAO.TextBaseFactory.loadInfoText("step1", this.LangId);
        }
    }

    private void LoadCountry()
    {
        using (SqlConnection conn = new SqlConnection(DAO.Connection.CONN_STRING1))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("SELECT id, short, name FROM dbo.Fn_GetAllPlaces(0, 1000000, 'id', 'asc', 2) WHERE isActive='true' Order By name asc", conn))
            {
                SqlDataReader dr = cmd.ExecuteReader();
                ddlCountry.Items.Add(new ListItem("", "0"));
                while (dr.Read())
                {
                    ddlCountry.Items.Add(new ListItem(dr["name"].ToString() + " - " + dr["short"].ToString(), dr["id"].ToString()));
                }
                dr.Close();
            }
        }
    }

    private void setAttributes()
    {
        tbAddress.Attributes.Add("validate", "true");
        tbCity.Attributes.Add("validate", "true");
        tbCompName.Attributes.Add("validate", "true");
        tbEmail.Attributes.Add("validate", "true");
        //tbPostCode.Attributes.Add("validate", "true");
        tbTelephone.Attributes.Add("validate", "true");
        tbExt.Attributes.Add("validate", "true");
        ddlCountry.Attributes.Add("validate", "true");
    }

    protected override void InitializeUI()
    {
        long langId = DAO.Connection.DEFAULT_LANGUAGE;
        if (Session["language"] != null)
            long.TryParse(Session["language"].ToString(), out langId);

        this.LangId = Convert.ToInt32(langId);
    }
}